<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>test2</title>
<link rel="stylesheet" type="text/css" href="<{$ipath}>wx/style/request.css" media="all" />
<script type="text/javascript"  src="<{$ipath}>public/js/head.js"></script>
<script type="text/javascript"  src="<{$ipath}>wx/js/jquery.min.js"></script>
<script type="text/javascript"  src="<{$ipath}>wx/js/ajaxfileupload.js"></script>
<script>
function showwxput(n,obj){
	for(var i=1;i<6;i++){
		$(".putcon"+i).hide();
		$(".ptit i").removeClass("select");
	}
	var temarr=new Array();
	temarr[1]="txt";
	temarr[2]="img";
	temarr[3]="voice";
	temarr[4]="video";
	temarr[5]="news";
	$(obj).parent().parent().parent().find(".putcon"+n).show();
	$("#type").val(n);
	$(obj).parent().parent().parent().find("."+temarr[n]+"icon i").addClass("select");
}
function save_smart(n,fname){
	var url='?g=wx&m=weixin&a=savesmart';
	var data={};
	var dl=$("#datalist").children("span");
	if($("#showlist>li").length >= 5){
		alert('一个规则最多可以增加5条回复');
		return false;
	}
	data.type = n;
	if(n==1){
		data.content = $("#content").val();
	}else if(n==2){
		data.type = '2';
	}else if(n==3){
		data.title = $("#vtit").val();
		data.type = '3';
	}else if(n==4){
		data.title = $("#tit").val();
		data.desc = $("#desc").val();
		data.type = '4';
	}
	if(n>1){
		$.ajaxFileUpload({
			url:url,
			dataType:'json',
			fileElementId:fname,
			type:'post',
			secureuri:false,
			data:data,
			success:function(data){
				if(data.error==1000 || data.error=='1000'){
					if(data.type==2 || data.type=='2'){
						$("#showlist").append('<li><img src="'+data.msg+'" width="80" /><input type="hidden" name="rmedia[]" value="'+data.media_id+'" /><em><a class="delicon" onclick="delmedia(this)"></a></em></li>');
						dl.eq(1).html(parseInt(dl.eq(1).html())+1);
					}
					if(data.type==3 || data.type=='3'){
						$("#showlist").append('<li><audio controls src="'+data.msg+'">您的浏览器不支持H5音频播放</audio><input type="hidden" name="rmedia[]" value="'+data.media_id+'" /><em><a class="delicon" onclick="delmedia(this)"></a></em></li>');
						dl.eq(2).html(parseInt(dl.eq(2).html())+1);
					}
					if(data.type==4 || data.type=='4'){
						$("#showlist").append('<li><video controls src="'+data.msg+'">您的浏览器不支持H5音频播放</audio><input type="hidden" name="rmedia[]" value="'+data.media_id+'" /><em><a class="delicon" onclick="delmedia(this)"></a></em></li>');
						dl.eq(3).html(parseInt(dl.eq(3).html())+1);
					}
				}else{
					alert(data.msg);
					return false;
				}
			}
		});
	}else{
		$.post(url,data,function(data){
			if(data.error==1000 || data.error=='1000'){
				$("#showlist").append('<li>'+data.msg+'<input type="hidden" name="rtxt[]" value="'+data.msg+'" /><em><a class="delicon" onclick="delmedia(this)"></a></em></li>');
				$("#content").val('');
				dl.eq(0).html(parseInt(dl.eq(0).html())+1);
			}else{
				alert(data.msg);
				return false;
			}
		},'json');
	}
}

function showeditmode(wxrinfo){
	var j=0;
	var ischeck='';
	var ritem='';
	var str='<form action="?g=wx&m=weixin&a=rsmart" method="post" target="hiddfrm">';
	str+='<div class="input">';
	if(typeof(wxrinfo.title)=='undefined'){
		str+='<ul>规 则 名：<input type="text" name="title" /></ul>';
	}else{
		str+='<ul>规 则 名：<input type="text" name="title" value="'+wxrinfo.title+'" /></ul>';
	}
	str+='<ul>关键词设置:<em onclick="addtkey(this)"><a>添加关键词</a></em>';
	str+='<dl id="tkeylist">';
	if(typeof(wxrinfo.keylist) == 'undefined' || typeof(wxrinfo.keylist)==null){
	str+='<li>关 键 词:<input type="text" name="tkey[0]" /><em><input type="checkbox" name="mode[1]" value="1" />模糊匹配 <a class="delicon" onclick="deltkey(this)"></a></em></li>'
	}else{
		for(ritem in wxrinfo.keylist){
			if(wxrinfo.keylist[ritem].mode==1 || wxrinfo.keylist[ritem].mode=='1'){
				ischeck='checked';
			}else{
				ischeck='';
			}
			str+='<li>关 键 词:<input type="text" name="tkey['+j+']" value="'+wxrinfo.keylist[ritem].tkey+'" /><em><input '+ischeck+' type="checkbox" name="mode['+j+']" value="1" />模糊匹配<a class="delicon" onclick="deltkey(this)"></a></em></li>'
			j++;
		}
	}
	str+='</dl></ul>'
	if(wxrinfo.mode==1 || wxrinfo.mode=='1'){ischeck='checked';}
	//str+='<ul>添加回复内容：<em><input name="isall" type="checkbox" value="1" '+ischeck+' />回复全部</em></ul></div>';
	str+='<ul class="ptit">';
	str+=' <li class="txticon"><a onClick="showwxput(1,this)"><i class="icon select"></i><span>文字</span></a></li> <li class="imgicon"><a onClick="showwxput(2,this)"><i class="icon"></i>图片</a></li><li class="voiceicon"><a onClick="showwxput(3,this)"><i class="icon"></i>语音</a></li><li  class="videoicon"><a onClick="showwxput(4,this)"><i class="icon"></i>视频</a></li><li class="newsicon"><a onClick="showwxput(5,this)"><i class="icon"></i>图文</a></li></ul>';
	str+='<ul class="pcon putcon1"><textarea name="content" id="content"></textarea><h5><input type="button" value="添加文字" onClick="save_smart(1)" class="wxsubmit" style="display:inlink-block" /></h5></ul>';
	str+='<ul class="pcon putcon2">';
	str+='<div><li class="selmate"><a onclick="getmedialist(2,this)"><i></i><h2 class="space_bottom">从素材库选择</h2></a></li>';
	str+='<li class="selmate"><i><input type="file" name="img" id="img" class="fhidden" /></i><h2 class="space_bottom">上传图片</h2></li></div>';
	str+='<h5><input type="button" value="添加图片" onClick="save_smart(2,\'img\')" class="wxsubmit" style="display:inlink-block" /></h5></ul>';
	str+='<ul class="pcon putcon3">';
	str+='<div><li class="selmate"><a onclick="getmedialist(3,this)"><i></i><h2 class="space_bottom">从素材库选择</h2></a></li>';
	str+='<li class="selmate"><i><input type="file" name="voice" id="voice" class="fhidden" /></i><h2>上传语音</h2><dd style="margin-bottom:30px;">语音标题：<input type="text" placeholder="请输入语音文件标题" id="vtit" name="vtit" size="100" /></dd></li></div>';
	str+='<h5><input type="button" value="添加语音" onClick="save_smart(3,\'voice\')" class="wxsubmit" style="display:inlink-block" /></h5></ul>';
	str+='<ul class="pcon putcon4">';
	str+='<div><li class="selmate"><a onclick="getmedialist(4,this)"><i></i><h2 class="space_bottom">从素材库选择</h2></a></li>';
	str+='<li class="selmate"><i><input type="file" name="video" id="video" class="fhidden" /></i><h2>上传视频</h2><dd>视频标题：<input type="text" placeholder="请输入视频文件标题" name="tit" size="100" id="tit" /></dd><dd style="margin-bottom:5px;">视频说明：<input type="text" placeholder="请输入视频文件简介" name="desc" size="255" id="desc" /></dd></li></div>';
	str+='<h5><input type="button" value="添加视频" onClick="save_smart(4,\'video\')" class="wxsubmit" style="display:inlink-block" /></h5></ul>';
	str+='<ul class="pcon putcon5">';
	str+='<div><li class="selmate"><a onclick="getmedialist(5,this)"><i></i><h2 class="space_bottom">从素材库选择</h2></a></li>';
	str+='<li class="selmate"><a href="?g=wx&m=weixin&a=wxnews" target="_blank"><i></i><h2 class="space_bottom">添加图文</h2></a></li></div>';
	str+='</ul><ul id="showlist">';
	if(typeof(wxrinfo.media) == 'undefined' || typeof(wxrinfo.media)==null){
		str+='';
	}else{
		if(typeof(wxrinfo.media.txt) != 'undefined'){
			for(ritem in wxrinfo.media.txt){
				str+='<li>'+wxrinfo.media.txt[ritem]+'<input type="hidden" name="rtxt[]" value="'+wxrinfo.media.txt[ritem]+'" /><em><a class="delicon" onclick="delmedia(this)"></a></em></li>';
			}
		}
		if(typeof(wxrinfo.media.media) != 'undefined'){
			for(ritem in wxrinfo.media.media){
				if(wxrinfo.media.media[ritem].type=='img'){
					str+='<li><img src="'+wxrinfo.media.media[ritem].url+'" width="80" /><input type="hidden" name="rmedia[]" value="'+wxrinfo.media.media[ritem].media_id+'" /><em><a class="delicon" onclick="delmedia(this)"></a></em></li>';
				}else if(wxrinfo.media.media[ritem].type=='voice'){
					str+='<li><audio controls src="'+wxrinfo.media.media[ritem].url+'">您的浏览器不支持H5音频播放</audio><input type="hidden" name="rmedia[]" value="'+wxrinfo.media.media[ritem].media_id+'" /><em><a class="delicon" onclick="delmedia(this)"></a></em></li>';
				}else if(wxrinfo.media.media[ritem].type=='video'){
					str+='<li><video controls width="300" src="'+wxrinfo.media.media[ritem].url+'">您的浏览器不支持H5音频播放</video><input type="hidden" name="rmedia[]" value="'+wxrinfo.media.media[ritem].media_id+'" /><em><a class="delicon" onclick="delmedia(this)"></a></em></li>';
				}else if(wxrinfo.media.media[ritem].type=='news'){
					str+='<li><dl><img src="'+wxrinfo.media.media[ritem].url+'" width="100%" /><dd>'+wxrinfo.media.media[ritem].ntitle+'</dd></dl><input type="hidden" name="rmedia[]" value="'+wxrinfo.media.media[ritem].media_id+'" /><em style="margin-top:-20px"><a class="delicon" onclick="delmedia(this)"></a></em></li>';
				}
			}
		}
	}
	str+='</ul>';
	if(typeof(wxrinfo.tnum) =='undefined' && typeof(wxrinfo.inum) =='undefined' && typeof(wxrinfo.vnum) =='undefined' && typeof(wxrinfo.dnum) =='undefined'){
		str+='<h3 id="datalist">文字(<span data-type="1">0</span>) 图片(<span data-type="2">0</span>) 语音(<span data-type="3">0</span>) 视频(<span data-type="4">0</span>) 图文(<span data-type="5">0</span>)';
	}else{
	str+='<h3 id="datalist">文字(<span data-type="1">'+parseInt(wxrinfo.tnum)+'</span>) 图片(<span data-type="2">'+parseInt(wxrinfo.inum)+'</span>) 语音(<span data-type="3">'+parseInt(wxrinfo.vnum)+'</span>) 视频(<span data-type="4">'+parseInt(wxrinfo.dnum)+'</span>) 图文(<span data-type="5">'+parseInt(wxrinfo.nnum)+'</span>)';
	}
	if(typeof(wxrinfo.keylist) == 'undefined'){
		str+='<em><input type="hidden" value="0" class="tknum" />';
	}else{
		str+='<em><input type="hidden" value="'+(wxrinfo.keylist.length - 1)+'" class="tknum" />';
	}
	if(typeof(wxrinfo.id)){
		str+='<input type="hidden" name="id" value="'+wxrinfo.id+'"><input type="image" class="wxsubmit" value="保存" /> <input type="button" class="wxcancel" value="删除" onclick="delsmart('+wxrinfo.id+')" />';
	}else{
		str+='<input type="hidden" id="type" name="type" /><input type="image" class="wxsubmit" value="保存" />';
	}
	str+='</em></h3></form>';
	return str;
}

function geteditmodeinfo(id,obj){
	var wxrinfo={} 
	if(id>0){
		var url='?g=wx&m=weixin&a=getwxrbyid&id='+id;
		$.get(url,function(data){
			obj.parent("h3").next(".editmode").html(showeditmode(data.msg));
		},'json');
	}else{
		return {}
	}
}
$(function(){
	$(".wxinput h3 em").click(function(){
		if($(this).children("i").attr("class")=='jup'){
			var id=0;
			$(this).children("i").attr("class","jdown");
			if($(this).data("id")>0){id=$(this).data("id");}
			geteditmodeinfo(id,$(this));
			$(this).parent().parent().children(".editmode").show();
			$(this).parent().parent().children(".showmode").hide();
		}else{
			$(this).children("i").attr("class","jup");
			$(this).parent().parent().children(".editmode").hide();
			$(this).parent().parent().children(".showmode").show();
		}
	});
	
	
	$(".wxbutton").click(function(){
		$(this).parent("div").next(".wxinput").show();
		$(this).parent("div").next(".wxinput").children("h3").children("em").children("i").attr("class","jdown");
		$(this).parent("div").next(".wxinput").children(".editmode").html(showeditmode({}));
		$(this).parent("div").next(".wxinput").children(".editmode").show();
		$(this).parent("div").next(".wxinput").children(".showmode").hide();
	});
})
function addtkey(obj){
	var n = parseInt($(obj).parent().parent().parent().parent().find(".tknum").val()) + 1;
	if(n>9){
		alert('一个规则最多可设置10个关键词');
		return false;
	}
	$(obj).next("#tkeylist").append('<li>关 键 词:<input type="text" name="tkey['+n+']" /><em><input type="checkbox" name="islike['+n+']" />模糊匹配<a class="delicon" onclick="deltkey(this)"></a></em></li>');
	$(obj).parent().parent().parent().parent().find(".tknum").val(n);
}

function delsmart(id){
	if(confirm('确认这个素材吗?')){
		var url="?g=wx&m=weixin&a=delsmart&id="+id;
		$("#inputdata_"+id).remove();
		$.get(url,function(data){
			if(data==1000 || data=='1000'){
				alert('删除成功');
			}else{
				alert(data.msg);
				return false;
			}
		},'json');
	}else{
		return; 
	}
}
function delmedia(obj){
	if(confirm('确认这个素材吗?')){
		$(obj).parent().parent().remove();
	}
	return;
}
function deltkey(obj){
	if(confirm('确认删除这条关键词?')){
		$(obj).parent().parent().remove();
	}
	return;
}
</script>
<style>.topnav{ width:94%;margin:0 auto;padding-top:16px;font-size:14px;line-height:18px;}.topnav *{color:#333;}</style>
</head>

<body>
<div class="topnav"><a class="level-1" href="?g=index&m=index&a=platform">我的服务</a>><a class="level-2" href="?g=index&m=index&a=wxpla">微信公众号</a>><span class="level-3">回复设置</span></div>
<div id="wxrequest">
<h1>自动回复设置</h1>
<div class="wxnav">
<ul class="title"><a href="?g=wx&m=weixin&a=rreg"><li class="l">被添加自动回复</li></a><a href="?g=wx&m=weixin&a=rmsg"><li class="">消息自动回复</li></a><a href="?g=wx&m=weixin&a=rsmart"><li class="r select">关键词自动回复</li></a></ul>
<i class="info">公众平台如何设置关键词自动回复</i>
</div>
<div><ul class="wxbutton">添加规则+</ul></div>
<div class="wxinput" id="inputdata_0" style="display:none">
	<h3>新规则<em><i class="jdown"></i></em></h3>
    <div class="editmode">
    </div>
    <div class="showmode input">
        <ul>关 键 词：</ul>
        <ul>回复信息：0条(0条文字 0条图片 0条语音 0条视频 0条图文)</ul>
    </div>
</div>
<{section name=l loop=$list}>
	<div class="wxinput" id="inputdata_<{$list[l].id}>">
    	<h3>规则名称：<{$list[l].title}><em data-id="<{$list[l].id}>"><i class="jup"></i></em></h3>
        <div class="editmode">
    	</div>
        <div class="showmode input">
        	<ul>关 键 词：<{foreach item=v from=$list[l].keylist}> <span><{$v.tkey}></span> <{/foreach}></ul>
            <ul>回复信息：<{$list[l].allnum}>条(<{$list[l].tnum}>条文字 <{$list[l].inum}>条图片 <{$list[l].vnum}>条语音 <{$list[l].dnum}>条视频 <{$list[l].nnum}>条图文)</ul>
            <{if $list[l].isall==1}><ul>发送全部回复</ul><{/if}>
        </div>
    </div>
<{/section}>
</div>
<div id="shade"></div>
<div id="showmedialist" class="hidddiv">
	<h3>选择素材<em onClick="closeshowmedialist()"><i class="icon_close"></i></em></h3>
    <ul id="showimglist"></ul>
    <ul id="showvoicelist"></ul>
    <ul id="showvideolist"></ul>
    <ul id="shownewslist"></ul>
    <h4><input type="hidden" id="mediashowid" value="" /><input type="hidden" id="mediashowtoid" value="" /><input type="hidden" id="mediashowurl" value="" /><input type="hidden" id="selbytype" value="" /><input type="hidden" id="mediashowtomore" value="" /><input type="button" class="wxbutton_cancel" id="mediashowsetbutton" value="确认"> <input type="button" class="wxbutton_cancel" onClick="closeshowmedialist()" value="取消" /></h4>
</div>
<script>
function getmedialist(n,obj){
	var url;
	var type;
	var str='';
	var temp='';
	var id=$(obj).parent().parent().parent().parent().parent().parent().parent().children("h3").find("em").attr("data-id");
	if(id=='' || id==null || id=='undefined'){
		id=0;
	}else{
		id=parseInt(id);
	}
	if(n==2){
		type='img';
	}else if(n==3){
		type='voice';
	}else if(n==4){
		type='video';
	}else if(n==5){
		type='news';
	}else{
		alert('选择素材类型错误');
		return false;
	}
	$("#selbytype").val(n);
	url='?g=wx&m=weixin&a=getmedialist&type='+type;
	$.get(url,function(data){
		if(data=='' || data==null){
			str+='<li class="showmedia_nono">暂时没有素材</li>';
		}else{
			if(n==2){
				for(ritem in data){
					str+='<li class="showmedia_img" onclick="setmediashowid(\''+data[ritem].media_id+'\',\''+data[ritem].url+'\',this)"><img src="'+data[ritem].url+'" width="120" height="120" /></li>';
				}
			}else if(n==3){
				for(ritem in data){
					str+='<li class="showmedia_voice" onclick="setmediashowid(\''+data[ritem].media_id+'\',\''+data[ritem].url+'\',this)"><img src="<{$ipath}>wx/images/voice_stop.png" width="60px" onclick="playaudio(this)" /><audio src="'+data[ritem].url+'"></audio><span>'+data[ritem].title+'</span></li>';
				}
			}else if(n==4){
				for(ritem in data){
					str+='<li class="showmedia_video" onclick="setmediashowid(\''+data[ritem].media_id+'\',\''+data[ritem].url+'\',this)"><video src="'+data[ritem].url+'" controls width="200"></video><br>'+data[ritem].title+'<br>'+data[ritem].content+'</li>';
				}
			}else if(n==5){
				for(ritem in data){
					str+='<li class="showmedia_news" onclick="setmediashowid(\''+data[ritem].media_id+'\',\''+data[ritem].url+'\',this)"><dl><img src="'+data[ritem].url+'" width="100%"><dd>'+data[ritem].ntitle+'</dd></dl></li>';
				}
			}
			$("#show"+type+"list").append(str);
			$("#shade").show();
			$("#showmedialist").show();
			$("#show"+type+"list").show();
			$("#mediashowtoid").val(id);
		}
	},'json');
}
function playaudio(obj){
	if($(obj).next("audio").get(0).paused){
		$(obj).next("audio").get(0).play();
		$(obj).attr("src","<{$ipath}>wx/images/voice_play.gif");
	}else{
		$(obj).next("audio").get(0).pause();
		$(obj).attr("src","<{$ipath}>wx/images/voice_stop.gif");
	}
}
function closehidd(){
	$(".hidddiv").hide();
	$("#shade").hide();
}
function setmediashowid(mid,url,obj){
	$("#mediashowid").val(mid);
	$("#mediashowurl").val(url);
	$("#mediashowsetbutton").attr("class","wxbutton");
	$("#mediashowsetbutton").attr("onclick","setmedia()");
	$(obj).parent().find(".icon_issel").remove();
	$(obj).append('<i class="icon_issel"></i>');
	if($(obj).find("dd").length>0){
		$("#mediashowtomore").val($(obj).find("dd").html());
	}
}
function setmedia(){
	var type = $("#selbytype").val();
	var media_id=$("#mediashowid").val();
	var url=$("#mediashowurl").val();
	var id = $("#mediashowtoid").val();
	if(type==2){
		$("#inputdata_"+id).find("#showlist").append('<li><img src="'+url+'" style="max-height:80px;" /><input type="hidden" name="rmedia[]" value="'+media_id+'" /><em><a class="delicon" onclick="delmedia(this)"></a></em></li>');
		$("#inputdata_"+id).find("#datalist").children("span").eq(1).html(parseInt($("#inputdata_"+id).find("#datalist").children("span").eq(1).html()) + 1);
	}else if(type==3){
		$("#inputdata_"+id).find("#showlist").append('<li><audio controls src="'+url+'">您的浏览器不支持H5音频播放</audio><input type="hidden" name="rmedia[]" value="'+media_id+'" /><em><a class="delicon" onclick="delmedia(this)"></a></em></li>');
		$("#inputdata_"+id).find("#datalist").children("span").eq(2).html(parseInt($("#inputdata_"+id).find("#datalist").children("span").eq(2).html()) + 1);
	}else if(type==4){
		$("#inputdata_"+id).find("#showlist").append('<li><video width="300" controls src="'+url+'">您的浏览器不支持H5音频播放</audio><input type="hidden" name="rmedia[]" value="'+media_id+'" /><em><a class="delicon" onclick="delmedia(this)"></a></em></li>');
		$("#inputdata_"+id).find("#datalist").children("span").eq(3).html(parseInt($("#inputdata_"+id).find("#datalist").children("span").eq(3).html()) + 1);
	}else if(type==5){
		var title = $("#mediashowtomore").val();
		$("#inputdata_"+id).find("#showlist").append('<li><dl><img src="'+url+'" width="100%" /><dd>'+title+'</dd></dl><input type="hidden" name="rmedia[]" value="'+media_id+'" /><em style="margin-top:-20px;"><a class="delicon" onclick="delmedia(this)"></a></em></li>');
		$("#inputdata_"+id).find("#datalist").children("span").eq(4).html(parseInt($("#inputdata_"+id).find("#datalist").children("span").eq(4).html()) + 1);
	}
	closeshowmedialist();
}
function closeshowmedialist(){
	$("#shade").hide();
	$("#showmedialist").hide();
	$("#mediashowsetbutton").attr("onclick",'');
	$("#mediashowsetbutton").attr("class","wxbutton_cancel");
	$("#showmedialist").children("ul").html('');
	$("#showmedialist").children("ul").hide();
}
</script>
<iframe width="0" height="0" id="hiddfrm" name="hiddfrm" scrolling="no" frameborder="0" style="display:none"></iframe>
</body>
</html>
